package cn.zlh.ht.mapper;

import cn.zlh.ht.entity.Template;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Mapper
public interface TemplateMapper {

    void createTemplate(Template template);


    @Select("SELECT table_name, table_comment FROM information_schema.tables " +
            "WHERE table_schema = 'system' AND table_name LIKE 'template_%'")
    List<Map<String, String>> getAllTemplateTableName();


    @Select("select COLUMN_NAME, COLUMN_COMMENT from information_schema.columns " +
            "where table_schema = 'system' AND table_name = #{templateName} ")
    List<Map<String, String>> getFieldByTableName(String templateName);

    void insert(String tableName, String agreementId, Map<String, String> fields);

    @Select("SELECT * FROM ${tableName} WHERE agreement_id = #{agreementId}")
    Map<String, Object> getTemplateDataByAgreemetnId(String tableName, String agreementId);

    @Select("SELECT table_comment FROM information_schema.tables WHERE table_schema = 'system' AND table_name = #{tableName}")
    String getTemplateLabelCN(String tableName);

    @Select("SELECT COLUMN_NAME, COLUMN_COMMENT FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = #{tableName}")
    List<Map<String, Object>> getTemplateFieldsLabelCN(String tableName);
}
